<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class template polymorphic_allocator</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_container_header_reference.html#doxygen.boost_container_header_reference.polymorphic__allocator_8hpp" title="Header &lt;boost/container/pmr/polymorphic_allocator.hpp&gt;">
<link rel="prev" href="classboost_1_1container_1_1pmr_1_1monotonic__buffer__resource.html" title="Class monotonic_buffer_resource">
<link rel="next" href="polymorphic__allocator_8hpp_1a84424509f4a6f9f0b942a83105987165.html" title="Function template operator==">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="classboost_1_1container_1_1pmr_1_1monotonic__buffer__resource.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_container_header_reference.html#doxygen.boost_container_header_reference.polymorphic__allocator_8hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="polymorphic__allocator_8hpp_1a84424509f4a6f9f0b942a83105987165.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template polymorphic_allocator</span></h2>
<p>boost::container::pmr::polymorphic_allocator</p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../boost_container_header_reference.html#doxygen.boost_container_header_reference.polymorphic__allocator_8hpp" title="Header &lt;boost/container/pmr/polymorphic_allocator.hpp&gt;">boost/container/pmr/polymorphic_allocator.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">T</span> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1ad0f61dedfa1aad68224c180c23465185"></a><span class="identifier">value_type</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#id80-bb">public member functions</a></span>
  <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a903a6365cd6531b942274de4b54b9898"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1af72c72dc5d7c5d0b6e63108c8ef60f24"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><a class="link" href="classboost_1_1container_1_1pmr_1_1memory__resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1ab72be65f312262d47ae13d8a6f7d8cdd"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">&gt;</span> 
    <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a56ec51004c0912346adeee89c050fbcd"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a><span class="special">&lt;</span> <span class="identifier">U</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&amp;</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1ac766516e0a231fa87a1829a721fdf522"><span class="keyword">operator</span><span class="special">=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <span class="identifier">T</span> <span class="special">*</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1aac8a10e8f29b3faf7486c10c8f828a12"><span class="identifier">allocate</span></a><span class="special">(</span><span class="identifier">size_t</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a10b6b6944999587d998298f9d2d5eeb1"><span class="identifier">deallocate</span></a><span class="special">(</span><span class="identifier">T</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">class</span> <span class="special">...</span> Args<span class="special">&gt;</span> <span class="keyword">void</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a0a929452cae59a36bf63680a8b9b2bb4"><span class="identifier">construct</span></a><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">Args</span> <span class="special">&amp;&amp;</span><span class="special">...</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">&gt;</span> <span class="keyword">void</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a2a156baa95fff10b154ef87438870da7"><span class="identifier">destroy</span></a><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a9e571abe4380453452c8120ade93271e"><span class="identifier">select_on_container_copy_construction</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <a class="link" href="classboost_1_1container_1_1pmr_1_1memory__resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a52e04c3a93fa1beae71ee2b5a39a5de6"><span class="identifier">resource</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.8.14.25.3.4"></a><h2>Description</h2>
<p>A specialization of class template <code class="computeroutput"><a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code> conforms to the Allocator requirements. Constructed with different memory resources, different instances of the same specialization of <code class="computeroutput"><a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code> can exhibit entirely different allocation behavior. This runtime polymorphism allows objects that use <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> to behave as if they used different allocator types at run time even though they use the same static allocator type. </p>
<div class="refsect2">
<a name="id-1.3.8.14.25.3.4.3"></a><h3>
<a name="id80-bb"></a><code class="computeroutput">polymorphic_allocator</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a903a6365cd6531b942274de4b54b9898"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to <code class="computeroutput">get_default_resource()</code>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1af72c72dc5d7c5d0b6e63108c8ef60f24"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><a class="link" href="classboost_1_1container_1_1pmr_1_1memory__resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span> r<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Requires</strong></span>: r is non-null.</p>
<p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to r.</p>
<p><span class="bold"><strong>Throws</strong></span>: Nothing</p>
<p><span class="bold"><strong>Notes</strong></span>: This constructor provides an implicit conversion from memory_resource*. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1ab72be65f312262d47ae13d8a6f7d8cdd"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&amp;</span> other<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to other.resource(). </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">&gt;</span> 
  <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a56ec51004c0912346adeee89c050fbcd"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a><span class="special">&lt;</span> <span class="identifier">U</span> <span class="special">&gt;</span> <span class="special">&amp;</span> other<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to other.resource(). </p>
</li>
<li class="listitem">
<pre class="literallayout"><a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&amp;</span> 
<a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1ac766516e0a231fa87a1829a721fdf522"></a><span class="keyword">operator</span><span class="special">=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&amp;</span> other<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to other.resource(). </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">T</span> <span class="special">*</span> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1aac8a10e8f29b3faf7486c10c8f828a12"></a><span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_t</span> n<span class="special">)</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Returns</strong></span>: Equivalent to <code class="computeroutput">static_cast&lt;T*&gt;(m_resource-&gt;allocate(n * sizeof(T), alignof(T)))</code>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a10b6b6944999587d998298f9d2d5eeb1"></a><span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">T</span> <span class="special">*</span> p<span class="special">,</span> <span class="identifier">size_t</span> n<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Requires</strong></span>: p was allocated from a memory resource, x, equal to *m_resource, using <code class="computeroutput">x.allocate(n * sizeof(T), alignof(T))</code>.</p>
<p><span class="bold"><strong>Effects</strong></span>: Equivalent to m_resource-&gt;deallocate(p, n * sizeof(T), alignof(T)).</p>
<p><span class="bold"><strong>Throws</strong></span>: Nothing. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">class</span> <span class="special">...</span> Args<span class="special">&gt;</span> <span class="keyword">void</span> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a0a929452cae59a36bf63680a8b9b2bb4"></a><span class="identifier">construct</span><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span> p<span class="special">,</span> <span class="identifier">Args</span> <span class="special">&amp;&amp;</span><span class="special">...</span> args<span class="special">)</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Requires</strong></span>: Uses-allocator construction of T with allocator <code class="computeroutput">*this</code> and constructor arguments <code class="computeroutput">std::forward&lt;Args&gt;(args)...</code> is well-formed. [Note: uses-allocator construction is always well formed for types that do not use allocators. - end note]</p>
<p><span class="bold"><strong>Effects</strong></span>: Construct a T object at p by uses-allocator construction with allocator <code class="computeroutput">*this</code> and constructor arguments <code class="computeroutput">std::forward&lt;Args&gt;(args)...</code>.</p>
<p><span class="bold"><strong>Throws</strong></span>: Nothing unless the constructor for T throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">&gt;</span> <span class="keyword">void</span> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a2a156baa95fff10b154ef87438870da7"></a><span class="identifier">destroy</span><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span> p<span class="special">)</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Effects</strong></span>: p-&gt;~U(). </p>
</li>
<li class="listitem">
<pre class="literallayout"><a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a9e571abe4380453452c8120ade93271e"></a><span class="identifier">select_on_container_copy_construction</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Returns</strong></span>: Equivalent to <code class="computeroutput"><a class="link" href="classboost_1_1container_1_1pmr_1_1polymorphic__allocator.html#doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a903a6365cd6531b942274de4b54b9898">polymorphic_allocator()</a></code>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a class="link" href="classboost_1_1container_1_1pmr_1_1memory__resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span> <a name="doxygen.boost_container_header_reference.classboost_1_1container_1_1pmr_1_1polymorphic__allocator_1a52e04c3a93fa1beae71ee2b5a39a5de6"></a><span class="identifier">resource</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>
<p><span class="bold"><strong>Returns</strong></span>: m_resource. </p>
</li>
</ol></div>
</div>
</div>
</div>
<div class="copyright-footer">Copyright © 2009-2018 Ion Gaztanaga<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="classboost_1_1container_1_1pmr_1_1monotonic__buffer__resource.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_container_header_reference.html#doxygen.boost_container_header_reference.polymorphic__allocator_8hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="polymorphic__allocator_8hpp_1a84424509f4a6f9f0b942a83105987165.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
